<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ObjAddRef() / ObjRelease()</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../css/default.css" rel="stylesheet" type="text/css">
</head>
<body>


<h1>ObjAddRef() / ObjRelease() <span class="ver">[AHK_L 53+]</span></h1>

<p>增加或减少对象的引用数.</p>

<pre class="Syntax">ObjAddRef(Ptr)<br>ObjRelease(Ptr)</pre>
<h3>参数</h3>
<table class="info">
  <tr>
    <td>Ptr</td>
    <td>一种非托管的对象指针或 COM 接口指针.</td>
  </tr>
</table>

<h3>返回值</h3>
<p>这两个函数返回新的引用计数. 此值应该 <b>仅</b> 用于调试目的.</p>

<h3>相关</h3>
<p>尽管后面的文章讨论了适用于 COM 的引用计算, 但其中掩饰了通常也适用于 AutoHotkey 对象的重要概念和规则: <a href="http://msdn.microsoft.com/en-us/library/ms691379.aspx">IUnknown::AddRef</a>, <a href="http://msdn.microsoft.com/en-us/library/ms682317.aspx">IUnknown::Release</a>, <a href="http://support.microsoft.com/kb/104138">引用计数规则</a>.</p>

<h3>示例</h3>
<p>参见 <a href="ComObjConnect.htm#Examples">ComObjConnect</a>.</p>

<pre class="NoIndent">obj := Object()

<em>; The following two lines are equivalent:</em>
ptr1 := <a href="../Objects.htm#AddressCast">Object</a>(obj) ptr2 := ObjectToPointer(obj) ObjectToPointer(obj) { if !IsObject(obj) return "" ptr := &amp;obj ObjAddRef(ptr) return ptr }

<em>; Each pointer retrieved via Object() or ObjectToPointer() must be manually released ; to allow the object to be eventually freed and any memory used by it reclaimed.</em>
ObjRelease(ptr2) ObjRelease(ptr1)
</pre>

</body>
</html>
